package cn.gxljc.technology.store_management.mapper;

import cn.gxljc.technology.store_management.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
 **@author LuoShengYing
 **@date 2021/6/10
 * OrderMapper用于管理Order(订单)表
 */
@Mapper
public interface OrderMapper {

     // 通过订单ID查询对应的订单数据
    @Select("select * from `order` where `orderID` = #{orderID}")
    Order selectOrderByOrderID(int orderID);

    // 通过订单状态(isExamine)查询对应的订单数组
    @Select("select * from `order` where `isExamine` = #{isExamine}")
    List<Order> selectOrdersByIsExamine(int isExamine);

    // 通过年份与月份查询商品的月销售情况
    @Select("SELECT * FROM `order` WHERE YEAR(createdTime) = #{year} and MONTH(createdTime) = #{month} and wareID = #{wareID}")
    List<Order> selectOrdersByMonth(int wareID, int year, int month);

    // 通过年份查询商品的年销售情况


    // 新建订单,并注入自增的orderID到传入的Order对象中
    @Insert("insert `order` set `orderName` = #{orderName}, `wareID` = #{wareID}, `wareCount` = #{wareCount}, `createdTIme` = #{createdTime}")
    @Options(useGeneratedKeys = true, keyProperty = "orderID")
    void insertOrder(Order order);

    // 更新订单状态
    @Update("update `order` set `isExamine` = #{isExamine} where `orderID` = #{orderID}")
    boolean updateOrderIsExamine(int orderID, int isExamine);

    // 删除订单(仅在订单状态isExamine为0时，才能使用此方法删除)
    @Delete("delete from `order` where `orderID` = #{orderID} and `isExamine` = 0")
    boolean deleteOrder(int orderID);
}
